import urllib.request

# 如果有问题, url 后面加个 `/`, 才是完整的 url
# 但是现在好像可以访问.
url = 'http://www.baidu.com'
response = urllib.request.urlopen(url = url)

# 保存到文件
#  with open('tmp/baidu.html', 'w', encoding = 'utf8') as fp:
    #  fp.write(response.read().decode())
# 这样写更简洁(图片只能以二进制的方式存储)
#  with open('tmp/baidu2.html', 'wb') as fp:
    #  fp.write(response.read())

#  print(response)
print(response.read().decode()) # 不用 decode() 没法看, 太乱了
#  print(response.geturl())
#  print(dict(response.getheaders())) # 转成字典类型比较容易操作
#  print(response.getcode()) # 获取状态码

